package com.zklh.leetcode.tree.middle;

import com.zklh.leetcode.tree.model.TreeNode;

/**
 * @author ：tong nan
 * @date ：Created in 2021/5/11 19:01
 * @description ：用于在二叉搜索树中查询结点
 * @modifiedBy ：
 */
public class BinaryTreeSearcher {



    boolean search(TreeNode root, int target) {

        if(root == null) {
            return false;
        }

        if (root.val == target) {
            return true;
        }
        return search(root.left, target) || search(root.right, target);
    }

    public static void main(String[] args) {
        TreeNode root = new TreeNode(10);
        root.left = new TreeNode(5);
        root.right = new TreeNode(15);
        root.right.left = new TreeNode(11);
        root.right.right = new TreeNode(20);

        BinaryTreeSearcher searcher = new BinaryTreeSearcher();
        System.out.println(searcher.search(root, 20));


    }

}
